
public class FourSlot {
	
	public int[][] d = {{0,0}, {0,0}, {0,0}, {0,0}};
	public int[] li = {0,0};
	public int l = 0;
	public int r = 0;
	
	public static void main(String[] args) {
		FourSlot f = new FourSlot();
		f.new Write(5).run();
		f.new Read().run();
		System.out.println("Value: " + f.d[0][0] + f.d[0][1] + f.d[1][0] + f.d[1][1]);
	}
	
	
	class Read implements Runnable{
		public void run(){
			int y, rp, ri;
			rp = l;
			r = rp;
			ri = li[rp];
			y = d[rp][ri];
			System.out.println("Read value: " + y);
		}
	};
	
	class Write implements Runnable{
		
		private int w;
		
		public Write(int w){
			this.w = w;
		}
		
		public void run(){
			int wp, wi;
			wp = 1 - r;
			wi = 1 - li[wp];
			d[wp][wi] = w;
			li[wp] = wi;
			l = wp;
		}
	};
}


